package com.qin.mall.controller.productcontroller;

import com.qin.mall.common.api.CommonResult;
import com.qin.mall.common.api.MyBatisPlusPage;
import com.qin.mall.domain.PmsProductAttributeCategory;
import com.qin.mall.dto.PmsProductAttributeCategoryItem;
import com.qin.mall.openfeign.product.ProductAttributeCategoryFeigin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品属性结合分类
 * @author Leisure
 * create 2022 2022/11/19 16:13
 **/
@RestController
@RequestMapping("/productAttribute/category")
public class AttributeCategoryController {
    
    @Autowired
    private ProductAttributeCategoryFeigin attributeCategoryFeigin;

    //创建属性分类
    @PostMapping("/create")
    public CommonResult create(@RequestParam("name") String name){
        CommonResult count = attributeCategoryFeigin.create(name);
        return count;
    }

    //修改属性分类
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Long id, @RequestParam("name") String name){
        CommonResult count = attributeCategoryFeigin.update(id, name);
        return count;
    }

    //删除单个属性分类
    @GetMapping("/delete/{id}")
    public CommonResult deleteById(@PathVariable Long id){
        CommonResult count = attributeCategoryFeigin.deleteById(id);
        return count;
    }

    //获取单个属性分类
    @GetMapping("/")
    public CommonResult selectById(@RequestParam("id") Long id){
        CommonResult result = attributeCategoryFeigin.selectById(id);
        return result;
    }

    //分页查询属性分类
    @GetMapping("/list")
    public CommonResult<MyBatisPlusPage<PmsProductAttributeCategory>> selectPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                                 @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        CommonResult<MyBatisPlusPage<PmsProductAttributeCategory>> page = attributeCategoryFeigin.selectPage(pageNum, pageSize);
        return page;
    }

    //获取包含属性的属性分类、分类属性一起查出来
    @GetMapping("/list/withAttr")
    public CommonResult<List<PmsProductAttributeCategoryItem>> getListWithAttr(){
        CommonResult<List<PmsProductAttributeCategoryItem>> list = attributeCategoryFeigin.getListWithAttr();
        return list;
    }

    

}
